package com.macro.mall.demo.design.pattern.chain;

import cn.hutool.core.collection.CollectionUtil;
import lombok.Data;
import java.util.List;

@Data
public class Chain implements IChain {

    private int index = -1;

    private String chainStr;

    private Object context;

    private List<IResponsability> responsabilityList;

    @Override
    public boolean hasNext() {
        return CollectionUtil.isNotEmpty(this.responsabilityList) && ++index < this.responsabilityList.size();
    }

    @Override
    public IResponsability next() {
        if (this.responsabilityList.size() > index) {
            return this.responsabilityList.get(index);
        }
        return null;
    }

    @Override
    public void reset() {
        this.index = -1;
    }
}
